package com.nowcoder.community.entity;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
public class Event {
    // 事件类型 / kafka主题
    private String topic;
    // 触发事件的用户
    private int userId;
    // 事件目标对象
    private int entityType;
    private int entityId;
    private int entityUserId;
    private Date fireTime;
    // 其他数据
    private Map<String, Object> data;

    public Event() {
        fireTime = new Date();
        data = new HashMap<>();
    }

    public Event setTopic(String topic) {
        this.topic = topic;
        return this;
    }

    public Event setUserId(int userId) {
        this.userId = userId;
        return this;
    }

    public Event setEntityType(int entityType) {
        this.entityType = entityType;
        return this;
    }

    public Event setEntityId(int entityId) {
        this.entityId = entityId;
        return this;
    }

    public Event setEntityUserId(int entityUserId) {
        this.entityUserId = entityUserId;
        return this;
    }

    public Object getData(String key){
        return data.get(key);
    }

    public Event setData(String key, Object value) {
        this.data.put(key, value);
        return this;
    }
}
